package com.dz.usersystem.controller;

import cn.hutool.core.date.StopWatch;
import com.dz.usersystem.entity.FilmUser;
import com.dz.usersystem.entity.ListNode;
import com.dz.usersystem.service.FilmUserService;

import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static jdk.nashorn.internal.objects.NativeArray.indexOf;
import static jdk.nashorn.internal.objects.NativeArray.reverse;

@RestController
@Slf4j
public class text {

    @Resource
    private RedisTemplate redisTemplate;
    @Resource
    private FilmUserService filmUserService;

    @GetMapping(value = "text")
    public List<FilmUser> getCatch() {
        Object userAll = redisTemplate.opsForValue().get("userAll");
        return (List<FilmUser>) userAll;
    }

    @GetMapping(value = "text01")
    @Transactional
    public String transsctionl() {
        log.info("事务测试");
        FilmUser user = new FilmUser();
        user.setId("999");
        user.setUsername("root");
        user.setPassword("123");
        user.setPhone("101");
        boolean b = filmUserService.deleteById("999");
        log.info("boolean----" + b);
//        int t=9/0;
        log.info("测试结束");
        return "ok";
    }

    //
//    //lamdba表达式
//    public static void main(String[] args) {
//        List<String> list = Arrays.asList("张三","李四","王五","李六");
//
//        Collections.sort(list,(String s1,String s2)->{
//            return s2.compareTo(s1); //
//        });
//        list.stream().forEach(System.out::println);
//        Integer[] i =new Integer[]{1,2,3,4,5};
//        IntStream.range(1,3).forEach(System.out::print);
//
//        List<String> list1 = Arrays.asList("ll.ll","ss.ss");
//        list1.stream().flatMap(e->Stream.of(e.split("."))).forEach(System.out::println);
//
//
//
//        //stream的学习
//        //1.使用值进行创建
//        Stream<String> stream=  Stream.of("ll","sasd","aaaa","zzzz");
//        String[] arr= new String[]{"aaa","bbb","ccc"};
//        Stream.of(arr);
//
//
//    }
    public static int[] twoSum(int[] nums, int target) {
        int n = nums.length;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                if (nums[i] + nums[j] == target) {
                    return new int[]{i, j};
                }
            }
        }
        return new int[0];


    }

    public static int lengthOfLongestSubstring(String s) {

        char[] chars = s.toCharArray();
        int n = chars.length;
        int max = 0;
        if ("".equals(s) || " ".equals(s)) {
            return n;
        }
        Set<Character> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            set.clear();
            int len = 0;
            for (int j = i; j < n; j++) {
                if (!set.contains(chars[j])) {
                    len++;
                    set.add(chars[j]);
                    max = max > len ? max : len;
                } else {
                    break;
                }

            }

        }
        return max;


    }

    public static double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int[] nums;
        int m = nums1.length;
        int n = nums2.length;
        nums = new int[m + n];
        int i = 0, x = 0, c = 0;
        while (i != m + n) {
            if (x == m) {
                nums[i++] = nums2[c++];
            } else if (c == n) {
                nums[i++] = nums1[x++];
            } else {
                if (nums1[x] < nums2[c]) {
                    nums[i++] = nums1[x++];
                } else {
                    nums[i++] = nums2[c++];
                }
            }
        }
        for (int j = 0; j < nums.length; j++) {
            System.out.println(nums[j]);
        }

        if ((m + n) % 2 == 0) {
            return (nums[(m + n) / 2 - 1] + nums[(m + n) / 2]) / 2.0;
        } else {
            return (nums[(m + n + 1) / 2 - 1]);
        }


    }

    public static String longestPalindrome(String s) {
        int k;
        int max = 0;
        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            String s1 = "";
            k = 0;
            for (int j = i; j < s.length(); j++) {
                s1 += s.charAt(j);
//                StringBuilder str =new StringBuilder(s1);
                k++;
                if (reverse3(s1).equals(s1)) {
                    map.put(s1, k);
                    max = max > k ? max : k;
                }
            }

        }
        Iterator<String> iter = map.keySet().iterator();
        String cc = "";
        while (iter.hasNext()) {
            String key = iter.next();
            Integer value = map.get(key);
            if (value == max) {
                cc = key;
                break;
            }
        }
        return String.valueOf(cc);

    }

    public static String reverse3(String s) {

        char[] array = s.toCharArray();

        String reverse = "";  //新建空字符串

        for (int i = array.length - 1; i >= 0; i--) {
            reverse += array[i];
        }

        return reverse;

    }

    //整数反转
    public static int reverse(int x) {
        String s = String.valueOf(x);
        if (s.charAt(0) == '-') {
            StringBuilder ss = new StringBuilder(s.substring(1));
            StringBuilder reverse = ss.reverse();
            String s1 = "-" + reverse;
            double v = Double.parseDouble(s1);
            if (v >= Integer.MIN_VALUE && v <= Integer.MAX_VALUE) {
                return (int) Double.parseDouble(s1);
            } else {
                return 0;
            }
        } else if (x % 10 == 0) {
            StringBuilder ss = new StringBuilder(s);
            StringBuilder reverse = ss.reverse();
            String s1 = "";
            for (int i = 0; i < reverse.length(); i++) {
                if (reverse.charAt(i) == 0) {
                    continue;
                } else {
                    s1 = reverse.substring(i, reverse.length());
                    break;
                }
            }
            return Integer.parseInt(s1);
        } else {
            StringBuilder ss = new StringBuilder(s);
            String s1 = ss.reverse().toString();
            double v = Double.parseDouble(s1);
            if (v >= Integer.MIN_VALUE && v <= Integer.MAX_VALUE) {
                return (int) Double.parseDouble(s1);
            } else {
                return 0;
            }
        }
    }

    //字符串转整数
    public static int myAtoi(String s) {
        String ss = s.trim();
        if (ss.length() == 0) {
            return 0;
        }
        if (ss.length() == 1) {
            if ((ss.charAt(0) >= '0' && ss.charAt(0) <= '9')) {
                return Integer.parseInt(String.valueOf(ss));
            } else {
                return 0;
            }

        }
        StringBuilder s1 = new StringBuilder();
        if ((ss.charAt(0) == '-' || ss.charAt(0) == '+') && (ss.charAt(1) >= '0' && ss.charAt(1) <= '9')) {
            s1.append(ss.charAt(0));
            s1.append(ss.charAt(1));
        }
        if (s1.length() == 0) {
            for (int i = 0; i < ss.length(); i++) {

                if ((ss.charAt(i) >= '0' && ss.charAt(i) <= '9')) {
                    s1.append(ss.charAt(i));
                } else {
                    break;
                }
            }
        } else {
            for (int i = 2; i < ss.length(); i++) {

                if ((ss.charAt(i) >= '0' && ss.charAt(i) <= '9')) {
                    s1.append(ss.charAt(i));
                } else {
                    break;
                }
            }
        }
        if (Double.parseDouble("".equals(String.valueOf(s1)) ? "0" : String.valueOf(s1)) > Integer.MAX_VALUE) {
            return Integer.MAX_VALUE;
        } else if (Double.parseDouble("".equals(String.valueOf(s1)) ? "0" : String.valueOf(s1)) <= Integer.MIN_VALUE) {
            return Integer.MIN_VALUE;
        } else if (s1.length() > 0) {
            return Integer.parseInt(String.valueOf(s1));
        } else {
            return 0;
        }


    }

    //回文数
    public static boolean isPalindrome(int x) {
        String s = String.valueOf(x);
        int n =s.length();
        int t =0;
        boolean[] bo = new boolean[n/2];
        for (int i = 0; i < n/2; i++) {
            if (s.charAt(i) == s.charAt(n-1-i)){
                bo[i]=true;
                t++;
            }else {
                bo[i]=false;
            }
        }
        boolean b =false;
        if ( t== bo.length){
            b =true;
        }
        return b;

    }
    //盛水最多的容器
     // Multiply 乘
    public static int maxArea(int[] height) {
        int max =0;
        int iMultiply =0;
        int n =height.length;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                iMultiply = (Math.min(height[i],height[j]))*(j-i);
                max= Math.max(max,iMultiply);

            }
        }
        return  max;

    }
    //无重叠区间
    public static int eraseOverlapIntervals(int[][] intervals) {
        int ii=0;
        int n=intervals.length;
        ArrayList<int[]> list = new ArrayList<>();
        for (int i = 0; i <n ; i++) {
            for (int j = i+1; j < n; j++) {
                if(intervals[i][0] < intervals[j][0] && intervals[i][1] > intervals[j][1] ){
                    ii++;
                }

            }
        }



        return ii;

    }
    //最长公共前缀
    public static String longestCommonPrefix(String[] strs) {
        int n =strs.length;
        if(n==0){
            return "";
        }
        String str=strs[0];
        for (int i = 0; i < n; i++) {
                 if(str.length()==0){
                     return "";
                 }
                 String str1 = "";
                int  min = Math.min(str.length(), strs[i].length());
                 for (int j = 0; j < min; j++) {
                      if(str.charAt(j)==strs[i].charAt(j)){
                          str1+=str.charAt(j);
                      }else {
                          break;
                      }
                 }
                 str = str1;
             }

        return str;


    }
    //三数之和
    public static List<List<Integer>> threeSum(int[] nums) {
        List<List<Integer>> lists =new ArrayList<>();

        int n =nums.length;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = i+2; k < n; k++) {
                    if(nums[i]+nums[j]+nums[k]==0){
                        List<Integer> list =new ArrayList<>();
                        list.add(nums[i]);
                        list.add(nums[j]);
                        list.add(nums[k]);
                        for (int l = 0; l < lists.size(); l++) {
                            System.out.println();
//                            if(lists.get(l).contains(nums[i])&&lists.get(l).contains(nums[j])&&lists.get(l).contains(nums[k])){
//                                lists.add(list);
//                            }
                        }
                        lists.add(list);



                    }
                }

            }

        }
        return lists;

    }
   //26. 删除排序数组中的重复项
    public static int removeDuplicates(int[] nums) {
        List<Integer> list =new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            list.add(nums[i]);
        }

        HashSet set= new HashSet(list);
        list.clear();
        list.addAll(set);
        Collections.sort(list);
        for (int i = 0; i < list.size(); i++) {
            nums[i]=list.get(i);
        }
        return list.size();


    }

    public static int removeElement(int[] nums, int val) {
        int ans = 0;
        for(int num: nums) {
            if(num != val) {
                nums[ans] = num;
                ans++;
            }
        }
        return ans;

    }
    //28 实现 strStr()
    public static int strStr(String haystack, String needle) {
        int i=-1;
        int l=haystack.length();
        int n=needle.length();
        if(l==0&&n==0){
            return 0;
        }
        for (int j = 0; j <= l-n; j++) {
            String ss =haystack.substring(j,j+n);
            if(ss.equals(needle)){
                i=j;
                break;
            }
        }
        return  i;

    }
    //35. 搜索插入位置
    public static int searchInsert(int[] nums, int target) {
        List<Integer> list =new ArrayList<>();
        int n= nums.length;
        for (int i = 0; i < n; i++) {
            list.add(nums[i]);
        }
        list.add(target);


        HashSet set =new HashSet(list);
        list.clear();
        list.addAll(set);
        Collections.sort(list);
        int t=0;
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i)==target){
                t= i;
            }
        }
        return t;


    }
    // 53. 最大子序和
    public static int maxSubArray(int[] nums) {
      int n =nums.length;
      int max=nums[0];
      for (int i = 0; i < n; i++) {
            int sum = nums[i];
            if(sum > max) {
                max = Math.max(sum,max);
            }
            for (int j = i+1; j < n; j++) {
                   sum=sum+nums[j];
                   max = Math.max(sum,max);
            }

      }
      return max;

    }
    //    58. 最后一个单词的长度
    public static int lengthOfLastWord(String ss) {
        int t =0;
        String s =ss.trim();
        for (int i = s.length()-1; i >=0 ; i--) {
            if((s.charAt(i) >='A'&&s.charAt(i)<='Z')||(s.charAt(i) >='a'&&s.charAt(i)<='z')){
                t++;
            }else {
                break;
            }

        }
        return t;

    }
    //66. 加一
    public static int[] plusOne(int[] digits) {
        int n =digits.length;
        digits[n-1]=digits[n-1]+1;
        for (int i = n-1; i >= 0 ; i--) {
            if(digits[0]==10){
                int[] is =new int[n+1];
                is[0]=1;
                return is;
            }
            else if(digits[i]==10){
                digits[i-1]=digits[i-1]+1;
                digits[i]=0;
            }else {
                break;
            }
        }
        return digits;

    }
    //67. 二进制求和
    public static String addBinary(String a, String b) {

        Double a1 = Double.parseDouble(a);
        Double b1= Double.parseDouble(b);
        Double c =a1+b1;
        String s = String.valueOf(c);
        char[] chars = s.toCharArray();
        int n =chars.length;
        if(n <=1){
            if(chars[0]=='2'){
                return "10";
            }else {
                return String.valueOf(chars[0]);
            }
        }
        Boolean flag =false;
        for (int i =n-1; i >=0; i--) {
            if(chars[i]=='2'||chars[i]=='3'){
                Double db= Double.parseDouble(String.valueOf(chars[i-1]).trim())+1;
                Double db1= Double.parseDouble(String.valueOf(chars[i]).trim()) -2;
                chars[i-1]=String.valueOf(db).charAt(0);
                chars[i]=String.valueOf(db1).charAt(0);
            }
            if(chars[0]=='2'){
                flag = true;
                chars[0]='0';
            }
            if(chars[0]=='3'){
                flag = true;
                chars[0]='1';
            }
        }
        if (flag){
            StringBuilder stringBuilder =new StringBuilder(String.valueOf(chars));
            stringBuilder.insert(0,"1");
            return String.valueOf(stringBuilder);
        }
        return String.valueOf(chars);



    }


// 21. 合并两个有序链表
     public static class ListNode {
         int val;
          ListNode next;
         ListNode() {}
          ListNode(int val) { this.val = val; }
          ListNode(int val, ListNode next) { this.val = val; this.next = next; }

      }

     static class  Solution {
         ListNode head = new ListNode(0);

         public static ListNode mergeTwoLists(ListNode l1, ListNode l2) {
             ListNode head = new ListNode();
             ListNode newListNode = head;
             while (true) {
                 if (l1.next == null) {
                     newListNode.next = l2;
                     break;

                 } else if (l2.next == null) {
                     newListNode.next = l1;
                     break;
                 } else {
                     if (l1.val <= l2.val) {
                         newListNode.next = l1;
                         l1 = l1.next;

                     } else {
                         newListNode.next = l2;
                         l2 = l2.next;
                     }
                 }
             }
             return newListNode;

         }

         public void add(ListNode linkList1) {
             ListNode temp = head;
             while (true) {
                 if (temp.next == null) {
                     break;
                 }
                 temp = temp.next;
             }
             temp.next = linkList1;

         }

         public void selectAll() {
             if (head.next == null) {
                 System.out.println("lina biao wei kong");
                 return;
             }
             ListNode temp = head.next;
             while (true) {
                 System.out.println(temp);
                 if (temp.next == null) {
                     break;
                 }

                 temp = temp.next;
             }
         }
         //69. x 的平方根
         public static int mySqrt(int x) {
               int result = 0;
             for (int i = 1; i <= x/2+1; i++) {
                 if ((i*i-x)>0){
                     result=(i-1);
                     break;
                 }else if((i*i-x)==0){
                     result =i;
                     break;
                 }

             }
             return  result;

//             return (int) Math.sqrt(x);
         }
         //70. 爬楼梯
         public static int climbStairs(int n) {
             int[] ints =new int[n];
             if (n==1){
                 return 1;
             }

             ints[0]=1;
             ints[1]=2;

             for (int i = 2; i < n; i++) {
                 ints[i]=ints[i-1]+ints[i-2];
             }
             return ints[n-1];
         }
         //运算 2+3*2-1
         public static int yunSuan(String str) {
             Stack<Character> stack = new Stack<>();
             Stack<Character> stack1 = new Stack<>();
             int n = str.length();
             int result =0;
             for (int i = 0; i < n; i++) {
                 if(str.charAt(i)=='+'||str.charAt(i)=='-'||str.charAt(i)=='*'||str.charAt(i)=='/'){
                     if (stack1.empty()){
                         stack1.push(str.charAt(i));
                     }else {
                         if(youXianJi(stack1.peek()) >= youXianJi(str.charAt(i))){

                         }

                     }
                 }

                stack.push(str.charAt(i));


             }






             return result;
         }




//          public class ListNode {
//              int val;
//             ListNode next;
//              ListNode() {}
//              ListNode(int val) { this.val = val; }
//              ListNode(int val, ListNode next) { this.val = val; this.next = next; }
//          }
//
//
//             public ListNode deleteDuplicates(ListNode head) {
//
//                ListNode listNode =head;
//                if (head.next == null){
//                    System.out.println("链表为空");
//                    return null;
//                }
//
//                while (true){
//                    if(listNode.next == null){
//                        break;
//                    }
//                    if(listNode.next.val==listNode.next.next.val){
//                        listNode.next.next=listNode.next.next.next;
//                    }
//                    listNode=listNode.next;
//
//
//                }
//                return listNode;
//
//             }

         public static int youXianJi(char s){
             switch (s){
                 case '*':{
                     return 1;

                 }
                 case '/':{
                     return 1;

                 }case '+':{
                     return 2;

                 }case '-':{
                     return 2;
                 } default:{
                     return -1;
                 }

             }
         }
         //简单的迷宫

         public static boolean miGong(int[][] map , int i,int j){
             map[3][1] = 1;
             map[3][2] = 1;
             map[3][3] = 1;
             map[3][4] = 1;
             map[3][6] = 1;
             map[1][2] = 1;
             map[2][2] = 1;
             if (map[6][6]==2){
                 return true;
             }else {
               if (map[i][j]==0){
                   map[i][j]=2;
                   if (miGong(map,i+1,j)){
                       return true;
                   }else if(miGong(map,i,j+1)){
                       return true;
                   }else if (miGong(map,i-1,j)){
                       return true;
                   }else if(miGong(map,i,j-1)){
                       return true;
                   }else {
                       return false;
                   }
               }else {
                   return false;
               }
             }


         }
         //88. 合并两个有序数组
         public static void merge(int[] nums1, int m, int[] nums2, int n) {
             int[] nums = new  int[m+n];
             for (int i = 0,j=0,z=0; z < m+n; z++) {
                 if(i==m){
                     nums[z] = nums2[j];
                     j++;
                 }
                 else if (j == n){
                     nums[z] = nums1[i];
                     i++;
                 }

                 else if (nums1[i]<= nums2[j]){
                     nums[z] = nums1[i];
                     i++;
                 }else if (nums1[i] > nums2[j]){
                     nums[z] = nums2[j];
                     j++;

                 }


             }
             for (int i = 0; i < m+n; i++) {
                 nums1[i] = nums[i];
             }


         }
         //16. 最接近的三数之和
         public static int threeSumClosest(int[] nums, int target) {
             Arrays.sort(nums);
             int n =nums.length;
             int result = 1000;
             for (int i = 0; i < n-2; i++) {
                 for (int j = i+1; j < n-1; j++) {
                     for (int k = i+2; k < n; k++) {
                         int sum =nums[i]+nums[j]+nums[k];
                         if (sum == target){
                             return sum;
                         }
                         if (Math.abs(sum-target )< Math.abs(result -target)){
                             result =sum;
                         }

                     }

                 }

             }

             return  result;
         }
         //34. 在排序数组中查找元素的第一个和最后一个位置
         public static int[] searchRange(int[] nums, int target) {
             int n = nums.length;
             int t =Integer.MAX_VALUE;
             int a=0;
             boolean flag = false;
             for (int i = 0; i < n; i++) {
                 if (nums[i] ==target){
                     t= Math.min(t,i);
                     a++;
                     flag =true;
                 }

             }

             if (flag){
                 return new int[]{t,t+a-1};
             }else {
                 return new int[]{-1,-1};
             }

         }
         //41. 缺失的第一个正数
         public static int firstMissingPositive(int[] nums) {
             int min = 1;
             if (nums == null || nums.length == 0){
                 return min;
             }
             //先排序
             Arrays.sort(nums);
             int len = nums.length;
             for (int i = 0; i < len; i++) {
                 if ( nums[i] == min){
                     min++;
                 }
             }
             return min;
         }
         //29. 两数相除
         public static int divide(int dividend, int divisor) {


             return  dividend/divisor ;

         }
         //20. 有效的括号
         public static boolean isValid(String s) {
             Stack<Character> stack =new Stack<>();
             char[] chars = s.toCharArray();
             for (int i = 0; i < chars.length; i++) {
                 if (stack.size()==0){
                     stack.push(chars[i]);
                 }else if (getPipei(stack.peek(),chars[i])){
                     stack.pop();
                 }else {
                     stack.push(chars[i]);
                 }

             }

             if (stack.size()==0){
                 return true;
             }else {
                 return false;
             }

         }
         public static boolean getPipei(char c1, char c2){

             return (c1=='('&&c2==')') || (c1=='{'&&c2=='}') ||(c1=='['&&c2==']');

         }







         public static void main(String[] args) {
//             [1,1,3,4,5,5,5,5,5]
//             3
//           int[] ints1 =new int[]{1};
//             int i = firstMissingPositive(ints1);
             int i =divide(-2147483648,-1);
             String ss ="()[{}";
             boolean valid = isValid(ss);
             System.out.println(valid);




         }

     }


}
